package com.steve.xfood.service.impl;

import com.steve.xfood.repository.ProductCategoryRepository;
import com.steve.xfood.dataobject.ProductCategory;
import com.steve.xfood.service.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author steve
 * @date 2020/5/1 5:34
 */
@Service
public class ProductCategoryServiceImpl implements ProductCategoryService {
    @Autowired
    private ProductCategoryRepository productCategoryRepository;

    @Override
    public ProductCategory findOne(Integer id) {
        //return productCategoryRepository.findOne(id); springboot1.5
        /**
         * 查不到返回Null
         * 使用findById(orderId).get()方法会抛异常
         */
        return productCategoryRepository.findById(id).orElse(null);
    }

    @Override
    public List<ProductCategory> findAll() {
        return productCategoryRepository.findAll();
    }

    @Override
    public ProductCategory save(ProductCategory productCategory) {
        return productCategoryRepository.save(productCategory);
    }

    @Override
    public List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeList) {
        return productCategoryRepository.findByCategoryTypeIn(categoryTypeList);
    }
}
